﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Timesheet
{
    class Test51CTOSystem
    {
        private const string LOG_IN_URL = "http://home.51cto.com/index.php?s=/Index/doLogin";
        private const string SEND_SMS_URL = "http://home.51cto.com/index.php?s=/Notify/doSend";

        // Friend's ID
        public const string FRIEND_1_ID = "1805422";

        /// <summary>
        /// Log in to the system using given username and password
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static HttpWebResponse logIn(string account, string password)
        {
            //string postData = "username=" + account + "&password=" + password + "&lt=_cA1A7EC65-AD0E-875B-DF81-7A40B31D8473_kD5DA7BA0-C887-CF4E-C1BE-A96FE791E1FB&_eventId=submit&submit=LOGIN";
            //string postData = "email=" + account + "&passwd=" + password + "&reback=http%253A%252F%252Fwww.51cto.com%252F&button.x=62&button.y=19";
            //string method = "POST";
            
            IDictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("email",account);
            parameters.Add("passwd",password);
            parameters.Add("reback","http%253A%252F%252Fwww.51cto.com%252F");
            parameters.Add("button.x","62");
            parameters.Add("button.y","19");
            
            try
            {
                //return connectHydra(LOG_IN_URL, method, postData);
                return WebUtility.CreatePostHttpResponse(LOG_IN_URL, parameters);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }

        /// <summary>
        /// Send one message to given friend
        /// </summary>
        /// <param name="friendID"></param>
        /// <param name="subject"></param>
        /// <param name="content"></param>
        public static HttpWebResponse sendMessage(string friendID, string subject, string content)
        {
            //fri_ids=1805422&subject=Test&content=Hi%2C+I+am+testing+my+new+project%2C+please+ignore+this+message%2C+sorry+for+the+inconvenience.
            
            IDictionary<string, string> paras = new Dictionary<string, string>();
            paras.Add("fri_ids", friendID);
            paras.Add("subject", subject);
            paras.Add("content", content);
            try
            {
                return WebUtility.CreatePostHttpResponse(SEND_SMS_URL, paras);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }

        
    }
}
